<?php
 // Copyright (C) 2010-2011 Aron Racho <aron@mi-squred.com>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
 // as published by the Free Software Foundation; either version 2
 // of the License, or (at your option) any later version.
 $rule = $viewBean->rule ?>
 <?php $allowed = $viewBean->allowed?>
<?php $ruleId = $viewBean->id;?>
<?php $groupId = $viewBean->groupId;?>

<script language="javascript" src="<?php js_src('edit.js') ?>"></script>
<script type="text/javascript">

	function save_new(){
		$.post( "../super/rules/index.php?action=edit!submit_summary", $( "#frm_submit" ).serialize());
		$("#info").hide();
		$("#info2").show();		
	}
	
	function cancel(){
	$("#info2").hide();
	var vari = $("#rule_id").val();
	var url = '../super/rules/index.php?action=detail!view&id='+vari;
	$.get(url, 
		function(data){
			$("#info").html(data);
		});	
		$("#info").show();
	}
</script>

<table class="header">
  <tr>
        <td class="title"><?php echo $rule->id ? out( xl( 'Rule Edit' ) ) : out( xl( 'Rule Add' ) ); ?></td>
        <td>
            <!--a  class="css_button css_button" onclick="cancel();">
                <span><?php echo out( xl( 'Cancel' ) ); ?></span>
            </a-->
			<input type='button' value='<?php echo out( xl( 'Cancel' ) ); ?>' onclick='cancel();'>
			</input>
            <!--a href="#" class="iframe_medium css_button" id="btn_save" onclick="top.restoreSession();save_new();"><span><?php echo out( xl( 'Save' ) ); ?></span></a-->
			<input type='button' value='<?php echo out( xl( 'Save' ) ); ?>' onclick='save_new();'>
			</input>
        </td>
  </tr>
</table>

<div class="rule_detail edit summry text">
    <p class="header"><?php echo out( xl( 'Summary' ) ); ?> </p>

    <form action="index.php?action=edit!submit_summary" method="post" id="frm_submit" onsubmit="top.restoreSession()">
    <input type="hidden" name="id" id="rule_id" value="<?php echo $_REQUEST['id']; ?>"/>

    <p class="row">
    <span class="left_col colhead req" data-fld="fld_title"><?php echo out( xl( 'Title' ) ); ?></span>
    <span class="end_col"><input type="text" name="fld_title" class="field" id="fld_title" value="<?php echo out( $rule->title ); ?>"></span>
    </p>
    
    <p class="row">
    <span class="left_col colhead" data-fld="fld_ruleTypes[]"><?php echo out( xl( 'Type' ) ); ?></span>
    <span class="end_col">
        <?php foreach ( RuleType::values() as $type ) {?>
        <input name="fld_ruleTypes[]"
               value="<?php echo out( $type ); ?>"
               type="checkbox" <?php echo $rule->hasRuleType(RuleType::from($type)) ? "CHECKED": "" ?>>
        <?php echo out( RuleType::from($type)->lbl ); ?>
        <?php } ?>
    </span>
    </p>

    </form>
    
</div>

<div id="required_msg" class="small">
    <span class="required">*</span><?php echo out( xl( 'Required fields' ) ); ?>
</div>
